from libavg import avg
from config import Config

class WindPanel(avg.DivNode):
    
    # direction enum
    LEFT_TRIPLE = -3
    LEFT_DOUBLE = -2
    LEFT_SINGLE = -1
    ZERO = 0
    RIGHT_SINGLE = 1
    RIGHT_DOUBLE = 2
    RIGHT_TRIPLE = 3
    
    # images
    IMAGE_INCLUDE_PATH = "../data/img/"
    LEFT_TRIPLE_IMAGE  = IMAGE_INCLUDE_PATH + "t_l_720.png"
    LEFT_DOUBLE_IMAGE  = IMAGE_INCLUDE_PATH + "d_l_720.png"
    LEFT_SINGLE_IMAGE  = IMAGE_INCLUDE_PATH + "s_l_720.png"
    ZERO_IMAGE         = IMAGE_INCLUDE_PATH + "zero_720.png"
    #ZERO_IMAGE         = IMAGE_INCLUDE_PATH + ""
    RIGHT_SINGLE_IMAGE = IMAGE_INCLUDE_PATH + "s_r_720.png"
    RIGHT_DOUBLE_IMAGE = IMAGE_INCLUDE_PATH + "d_r_720.png"
    RIGHT_TRIPLE_IMAGE = IMAGE_INCLUDE_PATH + "t_r_720.png"
    
    # direction to image mapping
    image_map = {LEFT_TRIPLE : LEFT_TRIPLE_IMAGE, 
                 LEFT_DOUBLE : LEFT_DOUBLE_IMAGE,
                 LEFT_SINGLE : LEFT_SINGLE_IMAGE,
                 ZERO        : ZERO_IMAGE,
                 RIGHT_SINGLE :  RIGHT_SINGLE_IMAGE,
                 RIGHT_DOUBLE : RIGHT_DOUBLE_IMAGE,
                 RIGHT_TRIPLE : RIGHT_TRIPLE_IMAGE}
    
    # vector for single directional wind influence
    # multiples for double and triple
    kineticEnergy = 10
    
    # private variables
    __windDirection = ZERO
    __windIcon = None
    
    def __init__(self, size, parent):
        
        # init parent divNode
        avg.DivNode.__init__(self, size=(Config.ctrlHeight, Config.ctrlWidth), parent=parent)
        
        # set icon
        self.__windIcon = avg.ImageNode(pos = (Config.windUpperLeft), 
                                href = WindPanel.image_map[WindPanel.ZERO], parent=self)
        
    def setDirection(self, direction):
        # check boundaries
        if direction >= WindPanel.LEFT_TRIPLE and direction <= WindPanel.RIGHT_TRIPLE:
            self.__windDirection = direction            
        else:
            self.__windDirection = WindPanel.ZERO
        
        # set icon image
        self.__windIcon.active = False
        self.__windIcon = avg.ImageNode(pos = (Config.windUpperLeft), 
                                        href = WindPanel.image_map[direction], parent=self)
        
    def resetDirection(self): # WIRD NICHT BENUTZT
        self.__windDirection = WindPanel.ZERO
        
    def getDirectionVector(self): # GEBEN WINDRICHTUNG * BEWEGUNGSENERGIE ZURUECK
        return self.__windDirection * WindPanel.kineticEnergy
    
    def getDirection(self): # GEBEN WINDRICHTUNG AUS
        return self.__windDirection